<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
       $this->display();
    }

    public function register(){     
       		$user = D("Users");
         if ($user->create())
          {

              if ($_FILE['photo']['error']==0) {
             $photoinfo=$this->upload();//将临时文件保存到指定的位置
            $user->photo=$photoinfo['photo']['savename'];
            }else{
            $user->photo = 'default.jpg';}
            if (false !== $user->add())
             {
                  $this->success('注册成功！', '../../Admin/index/users');
             } 
             else 
                {         $this->error('数据错误');   }
            }
                else {            
                     $this->error($user->getError());
                     }  
    }
    public function upload(){
        $upload= new \Think\Upload();
        $upload->maxSize = 3145728;
        $upload->exts =array('jpg','gif','png','jpeg');
        $upload->rootPath ='./Public/Uploads/photo/';
        $upload->autoSub=false;
        $info=$upload->upload();
        if(!$info){
            $this->error($upload->getError());
        }
        else{
            return $info;
        }
    }

}